package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.atguigu.tingshu.album.mapper.BaseCategory1Mapper;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

    @Autowired
    private BaseCategoryService baseCategoryService;



    @Operation(summary = "获取分类数据")
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList() {
        List<JSONObject> baseCategoryList = baseCategoryService.getBaseCategoryList();
        return Result.ok(baseCategoryList);
    }


    @Operation(summary = "获取标签属性")
    @GetMapping("/findAttribute/{id}")
    public Result<List<BaseAttribute>> findAttribute(@PathVariable("id") Long id) {
        List<BaseAttribute> attribute = baseCategoryService.findAttribute(id);
        return Result.ok(attribute);
    }

    @Operation(summary = "根据三级分类id获取分类对象")
    @GetMapping("/getCategoryView/{category3Id}")
    public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id) {
        BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
        return Result.ok(baseCategoryView);
    }

    /**
     * 根据一级分类id获取属性和属性值
     *
     * @param id
     * @return
     */
    @Operation(summary = "根据一级分类id获取属性和属性值")
    @GetMapping("/getBaseCategoryList/{id}")
    public Result getBaseCategoryList(@PathVariable Long id) {
        JSONObject baseCategory = baseCategoryService.getBaseCategory(id);
        return Result.ok(baseCategory);
    }

    /**
     * 获取一级分类下的三级分类
     *
     * @param category1Id
     * @return
     */
    @Operation(summary = "获取一级分类下的三级分类")
    @GetMapping("/findTopBaseCategory3/{category1Id}")
    public Result<List<BaseCategory3>> findChannel(@PathVariable Long category1Id) {
        List<BaseCategory3> channelCategory3 = baseCategoryService.findChannel(category1Id);
        return Result.ok(channelCategory3);
    }

    /**
     * 获取全部一级分类
     *
     * @return
     */
    @Operation(summary = "获取全部一级分类")
    @GetMapping("/findAllCategory1")
    public Result<List<BaseCategory1>> findAllChannel1() {
        List<BaseCategory1> BaseCategory1List = baseCategoryService.list();
        return Result.ok(BaseCategory1List);
    }
}

